package com.cet.designapplication.decorator.strategy;

import com.cet.designapplication.pojo.Products;
import com.cet.designapplication.repo.ProductsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author NSOC
 */
@Component
public class NormalScoreAndRegBagSendHandler implements ScoreAndRegBagSendStrategy{

    @Autowired
    private ProductsRepository productsRepository;

    @Override
    public int getServiceLevel() {
        return 0;
    }

    @Override
    public void sendScoreAndRegBag(String productId, BigDecimal price) {
        int score = Math.round(price.floatValue()) / 100;
        System.out.println("正常处理,为用户更新积分! score = " + score);
        Products product = productsRepository.findByProductId(productId);
        if (product != null && product.getSendRedBag() == 1) {
            System.out.println("正常处理，为用户发送红包！ productId = " + productId);
        }
    }
}
